Current Location: Home> Function Categories> mt_rand

mt_rand

Generate better random numbers
Name:mt_rand
Category:math
Programming Language:php
One-line Description:Use the Mersenne Twister algorithm to return random integers.

Definition and usage

mt_rand() uses the Mersenne Twister algorithm to return random integers.

Example

In this example, we will return some random numbers:

 <?php
echo ( mt_rand ( ) ) ;
echo ( mt_rand ( ) ) ;
echo ( mt_rand ( 10 , 100 ) ) ;
?>

Try it yourself

grammar

 mt_rand ( min , max )

illustrate

If no optional parameters min and max are provided, mt_rand() returns a pseudo-random number between 0 and RAND_MAX. For example, if you want a random number between 5 and 15 (including 5 and 15), use mt_rand(5, 15).

Many old libc random number generators have some uncertain and unknown characteristics and are very slow. The rand() function of PHP uses the libc random number generator by default. mt_rand() function is used informally to replace it. This function uses a known feature in Mersenne Twister as a random number generator, which can produce random values ​​at an average speed of four times faster than rand() provided by libc.

Similar Functions
Popular Articles